﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WuDada.Core.Member;
using WuDada.Core.Member.Service;
using WuDada.Core.Member.Domain;
using WuDada.Core.Post.Domain;
using WuDada.Core.Post;
using WuDada.Core.Post.Service;

public partial class login : System.Web.UI.Page
{
    private MemberFactory m_MemberFactory;
    private IMemberService m_MemberService;
    private SessionHelper m_SessionHelper;

    protected void Page_Load(object sender, EventArgs e)
    {
        m_MemberFactory = new MemberFactory();
        m_MemberService = m_MemberFactory.GetMemberService();
        m_SessionHelper = new SessionHelper();

        if (!IsPostBack)
        {
        }
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        string confirmationCode = txtSafeCode.Text.Trim();
        if (confirmationCode.ToUpper().Equals(Session["FrontCaptcha"].ToString().ToUpper()))
        {
            MemberVO memberVO = m_MemberService.GetMemberByLoginId(txtLoginId.Text.Trim());

            if (memberVO != null && memberVO.Password.Equals(txtPassword.Text.Trim()))
            {
                if (!memberVO.Status.Equals("1"))
                {
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("登入失敗，帳號停權中"), false);
                    return;
                }
                else
                {
                    m_SessionHelper.Member = memberVO;
                    Response.Redirect("index.aspx");
                    return;
                }
            }

            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("登入失敗，帳號或密碼錯誤"), false);
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "js", JavascriptUtil.AlertJS("驗證碼輸入錯誤。"), false);
        }
    }
}